package com.k12.user.controller;

import com.k12.user.model.entity.SysDept;
import com.k12.user.service.SysDeptService;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
/**
 * 部门表(SysDept)表控制层
 *
 * @author makejava
 * @since 2025-07-28 20:53:09
 */
@RestController
@RequestMapping("sysDept")
public class SysDeptController {
    /**
     * 服务对象
     */
    @Resource
    private SysDeptService sysDeptService;

    /**
     * 分页查询
     *
     * @param sysDept 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping("getAllDept")
    public List<SysDept> queryByPage(SysDept sysDept) {
        return this.sysDeptService.queryByPage(sysDept);
    }




    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("getOneDept/{id}")
    public SysDept queryById(@PathVariable("id") Long id) {
        return this.sysDeptService.queryById(id);
    }


    @GetMapping("getOneDept")
    public SysDept getOneDept(@RequestParam("deptId")Long deptId,@RequestParam("tenantId")String tenantId) {
        return this.sysDeptService.getOneDept(tenantId,deptId);
    }


    @GetMapping("selectNormalChildrenDeptById")
    public int selectNormalChildrenDeptById(@RequestParam("deptId")Long deptId,@RequestParam("tenantId")String tenantId) {
        return this.sysDeptService.selectNormalChildrenDeptById(tenantId,deptId);
    }

    @GetMapping("hasChildByDeptId")
    public int hasChildByDeptId(@RequestParam("deptId")Long deptId,@RequestParam("tenantId")String tenantId) {
        return this.sysDeptService.hasChildByDeptId(tenantId,deptId);
    }

    @GetMapping("deleteDeptById")
    public int deleteDeptById(@RequestParam("deptId")Long deptId,@RequestParam("tenantId")String tenantId) {
        return this.sysDeptService.deleteDeptById(tenantId,deptId);
    }




    /**
     * 新增数据
     *
     * @param sysDept 实体
     * @return 新增结果
     */
    @PostMapping("insertDept")
    public SysDept add(SysDept sysDept) {
        return this.sysDeptService.insert(sysDept);
    }

    /**
     * 编辑数据
     *
     * @param sysDept 实体
     * @return 编辑结果
     */
    @PostMapping("updateDept")
    public SysDept edit(SysDept sysDept) {
        return this.sysDeptService.update(sysDept);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("deleteDept")
    public Boolean deleteById(Long id) {
        return this.sysDeptService.deleteById(id);
    }

}

